package com.itheima.reggie.common;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {


    @Override
    public void insertFill(MetaObject metaObject) {
        setFieldValByName("createTime", LocalDateTime.now(),metaObject);
        setFieldValByName("updateTime", LocalDateTime.now(),metaObject);
//        setFieldValByName("createUser", Long.parseLong(Thread.currentThread().getName()),metaObject);
//        setFieldValByName("updateUser", Long.parseLong(Thread.currentThread().getName()),metaObject);
        setFieldValByName("createUser", BaseContext.getCurrentId(),metaObject);
        setFieldValByName("updateUser", BaseContext.getCurrentId(),metaObject);

    }

    @Override
    public void updateFill(MetaObject metaObject) {
        setFieldValByName("updateTime",LocalDateTime.now(),metaObject);
        //setFieldValByName("updateUser", Long.parseLong(Thread.currentThread().getName()),metaObject);
        setFieldValByName("updateUser", BaseContext.getCurrentId(),metaObject);
    }
}
